import { render } from 'vue'
import XtxConfirm from './xtx-confirm.vue'

// 准备一个装组件的div
// const vNnode = createVNode('div', { class: 'xtx-confirm-container' })
const vNnode = <div class='xtx-confirm-container' ></div>
// 渲染
render(vNnode, document.body)
// 获取 DOM 节点，用于挂载组件或卸载组件
const container = vNnode.el

const Confirm = ({ title, text }) => {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      resolve('点击确认')
      render(null, container)
    }
    const cancelCallBack = () => {
      reject(new Error('点击取消'))
      render(null, container)
    }
    // 动态创建组件
    const vNode = <XtxConfirm {...{ title, text, confirmCallback, cancelCallBack }}></XtxConfirm>
    render(vNode, container)
  })
}
export default Confirm
